package com.hitechbangla.fctu.utility;

import com.hitechbangla.fctu.base.aircraft.AircraftType;
import com.hitechbangla.fctu.utility.enumall.TurnDirection;
import com.hitechbangla.fctu.utility.Const;
import com.hitechbangla.fctu.utility.enumall.CommandType;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author deb kanti
 */
public class AircraftUtility 
{
    public static boolean isAngleBetweenCurrentAndTarget(float currentHeading, float nextHeading, float targetHeading, TurnDirection turnDirection)
    {
        float differenceCurrentToTarget, differenceCurrentToNext;
        
        if(turnDirection == TurnDirection.LEFT)
        {
            differenceCurrentToTarget = (Const.THREE_SIXTY_DEGREE + currentHeading - targetHeading) % Const.THREE_SIXTY_DEGREE;
            differenceCurrentToNext = (Const.THREE_SIXTY_DEGREE + currentHeading - nextHeading) % Const.THREE_SIXTY_DEGREE;
        }
        else // if direction is right
        {
            differenceCurrentToTarget = (Const.THREE_SIXTY_DEGREE + targetHeading - currentHeading) % Const.THREE_SIXTY_DEGREE;
            differenceCurrentToNext = (Const.THREE_SIXTY_DEGREE + nextHeading - currentHeading) % Const.THREE_SIXTY_DEGREE;
        }
        
        if(differenceCurrentToTarget > differenceCurrentToNext)
        {
            return true;
        }
        else
        {        
            return false;
        }
    } // end of isAngleBetweenCurrentAndTarget function
    
   public static boolean compareWithCommandRegEx(String command)
   {
       for(CommandType tempCommandType: CommandType.values())
       {
           Pattern patternRegEx = Pattern.compile(tempCommandType.getRegEx());
           Matcher matcher = patternRegEx.matcher(command);
           
           if(matcher.matches())
           { 
               return true;
           }           
       }
       return false;
   } // end of compareWithCommandRegEx function
    
}

/*
 float difference_current_target, difference_current_next;
if(turn == -1){//for left turn
difference_current_target = fmodf((THREE_SIXTY_DEGREE + current - target), THREE_SIXTY_DEGREE);
difference_current_next = fmodf((THREE_SIXTY_DEGREE + current - next), THREE_SIXTY_DEGREE);
}else{
difference_current_target = fmodf((THREE_SIXTY_DEGREE + target - current), THREE_SIXTY_DEGREE);
difference_current_next = fmodf((THREE_SIXTY_DEGREE + next - current), THREE_SIXTY_DEGREE);
}//end if else

if(difference_current_target > difference_current_next){
return true;
}
	return false;
 * 
 * 
 * 
 * 
 * 
 */
 
